<template>
     
</template>
  <script lang="ts" setup>
    import { reactive, ref, toRaw, unref, computed, onMounted,nextTick } from 'vue';
  
     
    import { useI18n } from '/@/hooks/web/useI18n';
    import { useMessage } from '/@/hooks/web/useMessage';
  
    import { useUserStore } from '/@/store/modules/user';
    import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin';
    import { useDesign } from '/@/hooks/web/useDesign'; 
    import { getCodeInfo } from '/@/api/sys/user';
    //import { onKeyStroke } from '@vueuse/core';
    import { useRoute } from 'vue-router';
    import { router } from '/@/router';
    import { PageEnum } from '/@/enums/pageEnum';
    const route = useRoute();
    console.log('route.query = ',route.query);
  
    
    const { t } = useI18n();
    const {createMessage, notification, createErrorModal } = useMessage(); 
    const userStore = useUserStore();
  
    const thirdType = ref('');
    const loading = ref(false); 
  
  // 根据token执行登录
  function doThirdLogin(token) {
   
      userStore.ThirdLogin({ token, thirdType: unref(thirdType) }).then((res) => {
        console.log('res====>doThirdLogin', res);
        if (res && res.userInfo) {
          notification.success({
            message: t('sys.login.loginSuccessTitle'),
            description: `${t('sys.login.loginSuccessDesc')}: ${res.userInfo.realname}`,
            duration: 3,
          });
        } else {
          requestFailed(res);
        }
      });
     
      router.replace({ path: PageEnum.BASE_LOGIN, query: route.query });
  }

  function requestFailed(err) {
    notification.error({
      message: '登录失败',
      description: ((err.response || {}).data || {}).message || err.message || '请求出现错误，请稍后再试',
      duration: 4,
    });
  }


    //初始化验证码
    onMounted(() => {
      let token = route.query.token;
      console.log('token==',token)
      thirdType.value =  route.query.source;
      if (typeof token === 'string') {
        console.log('typeof token ===string');
        //如果是字符串类型 说明是token信息
        if (token === '登录失败') {
          createMessage.warning(token);
        } else if (token.includes('绑定手机号')) {
            createMessage.warning('请绑定手机号');
        } else {
          console.log('doThirdLogin.....');
          doThirdLogin(token);
        }
      }  else {
        createMessage.warning('不识别的信息传递');
      }
       
    });
  </script>
  